package com.yanzhu.service.mapper;

import com.yanzhu.service.model.Comment;
import com.yanzhu.service.model.mix.VideoComment;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 21:46 2018/1/21
 * @Modified:
 */
@Mapper
public interface CommentMapper {
    @Insert("insert into comment(uid, vid, content, comment_time) values(#{uid}, #{vid}, #{content}, #{comment_time})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
    int insert(Comment comment);

    @Select("select c.vid, c.uid, c.content, c.comment_time, u.nickname, u.avatar" +
            " from comment c" +
            " left join user u on u.id = c.uid" +
            " where vid = #{vid}" +
            " order by c.comment_time desc" +
            " limit #{page}, ${size}")
    List<VideoComment> queryCommentList(@Param("vid") long vid, @Param("page") int page, @Param("size") int size);

    @Delete("delete from comment where id = #{id}")
    int deleteCommentById(@Param("id") long id);

    @Delete("delete from comment where uid=#{uid} and vid = #{vid}")
    int deleteCommentAll(@Param("uid") Long uid, @Param("vid") long vid);
}
